﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;
using System.Xml.Linq;
using System.IO;

namespace Infrastructure
{
    public class XmlParser:IDisposable
    {
        private static XmlParser parser;

        private  XDocument doc;

        private XmlParser() { }


        public static XmlParser Instance(Stream xmlStream)
        {
            if (parser != null)
            {
                XmlReader reader = XmlReader.Create(xmlStream);
                parser.doc = XDocument.Load(reader);
                return parser;
 
            }
            else
            {
                XmlParser instance = new XmlParser();
                XmlReader reader = XmlReader.Create(xmlStream);
                instance.doc = XDocument.Load(reader);
                parser = instance;
                return parser;
            }
        }

        public XDocument XmlDocument
        {
            get {  return doc; }
        }

 

        public void Dispose()
        {
            doc = null;
        }











      
    }
}
